<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<table class="layui-table">

    <thead>
    <tr>
        <!--<th>编号</th>-->
        <th>产品名称</th>
        <th>商家联系人</th>
        <th>进货价(元)</th>
        <th>售价(元)</th>
        <th>购买数量(个)</th>
        <th>总价(元)</th>
        <th>实际总价(元)</th>
        <th>订单号</th>
        <th>快递公司</th>
        <th>运单号</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {foreach $result as $val}
    <tr id="del{$val.id}">
        <!--<td>{$val.id}</td>-->
        <td>{$val.pname}</td>
        <td>{$val.linkman}</td>
        <td>{$val.purchaseprice}</td>
        <td>{$val.retailprice}</td>
        <td>{$val.number}</td>
        <td>{$val.total}</td>
        <td>{$val.actualtotal}</td>
        <td>{$val.ordernumber}</td>
        <td>{$val.express}</td>
        <td>{$val.oddnumber}</td>
        <td style="width: 120px">
            {if$val.status == 1}
                购买申请中
            {elseif $val.status == 2/}
                购买通过
            {elseif $val.status == 3/}
                邮寄中
            {elseif $val.status == 4/}
                货已到
            {else /}
                已完成
            {/if}
        </td>
        <td style="width: 250px">
            <button onclick="del({$val.id})" type="button" class="btn btn-danger btn-xs">删除</button>
            <button onclick="orderDetail({$val.id})" type="button" class="btn btn-primary btn-xs" >详情</button>
            {if $val.status == 1}
                <button onclick="status({$val.id},this)" type="button" id='t' class="btn btn-warning btn-xs" >通过</button>
            {elseif $val.status == 2 /}
                <button onclick="updatestatus({$val.id},this)" type="button" id='j' class="btn btn-warning btn-xs" >邮寄</button>
            {elseif $val.status == 3 /}
                <button onclick="reach({$val.id})" type="button"  class="btn btn-warning btn-xs" >已到</button>
            {else /}
                <button disabled type="button" class="btn btn-warning btn-xs">已完成</button>
            {/if}
            <!--{if $val.status == 4}-->
                <!--<button onclick="playmoney({$val.bid},{$val.ordernumber})" type="button" class="btn btn-warning btn-xs">打款</button>-->
            <!--{/if}-->
            <button type="button" onclick="express({$val.id})" class="btn btn-link btn-xs">添加物流信息</button>
            <button onclick="total({$val.id})" type="button" class="btn btn-info btn-xs">添加实际总价</button>
        </td>
    </tr>
    {/foreach}
    </tbody>
</table>
{$result->render()}
</body>
<script>
    //删除
    function del(id) {
        layer.confirm('你确定要删除吗',{bnt:['确定','取消']},
            function () {
                $.ajax({
                    url:"{:url('index/postpayment/delete')}",
                    data:'id='+id,
                    type:'post',
                    dataType:'json',
                    success:function (res) {
                        if(res.success){
                            layer.alert(res.success);
                            $("#del"+id).remove();
                        }
                        if(res.error){
                            layer.alert(res.error);
                        }
                    }
                });
            }
        );
    }
    //添加实际总价
    function total(id) {
        layer.prompt({title:'实际总价',formType:2},
            function (actualtotal) {
                $.ajax({
                    url:"{:url('index/postpayment/total')}",
                    data:'id='+id+'&actualtotal='+actualtotal,
                    type:'post',
                    dataType:'json',
                    success:function (res) {
                        if(res.success){
                            layer.alert(res.success,{bnt:['确定','取消']},
                                function () {
                                    window.location.reload();
                                },function () {
                                    window.location.reload();
                                }
                            );
                        }
                        if(res.error){
                            layer.alert(res.error);
                        }
                    }
                });
            }
        );
    }
    //订单详情
    function orderDetail(id) {
        window.location.href = "{:url('index/postpayment/orderDetail')}?id="+id;
    }
    //修改货物状态
    function status(id,th) {
        var status = th.id;
        $.ajax({
            url:"{:url('index/postpayment/updatestatus')}",
            data:"id="+id+"&status="+status,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert('操作成功',{btn:['确定']},
                        function () {
                            window.location.reload();
                        }
                    );
                }
            }
        });
    }
    //邮寄
    function updatestatus(id,th) {
        var status = th.id;
        $.ajax({
            url:"{:url('index/postpayment/updatestatus')}",
            data:"id="+id+"&status="+status,
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon: 1,time:2000},function () {
                        //获取窗口索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭弹出的子页面窗口
                        parent.layer.close(index);
                        window.parent.location.reload();
                    });
                }
                if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
    //打款
    function playmoney(bid,ordernumber) {
        window.location.href = "{:url('index/postsettlement/detail')}?bid="+bid+"&ordernumber="+ordernumber;
    }
    //已到
    function reach(id) {
        $.ajax({
            url:"{:url('index/postpayment/reach')}",
            data:"id="+id,
            type:"get",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,{bnt:['确定']},
                        function () {
                            window.location.reload();
                        }
                    );
                }
                if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
    //添加单号
    function express(id) {
        layer.open({
            type:2,
            title:"添加物流信息",
            anim:2,
            area: ['500px', '450px'],
            content:"{:url('index/postpayment/express')}?id="+id
        });
    }
    //查看库存
    function stock(id) {
        window.location.href = "{:url('index/postpayment/stock')}?id="+id;
    }
</script>
</html>